<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: Fourier Transform</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d5/d10/tutorial_js_root.html">OpenCV.js Tutorials</a></li><li class="navelem"><a class="el" href="../../d2/df0/tutorial_js_table_of_contents_imgproc.html">Image Processing</a></li><li class="navelem"><a class="el" href="../../db/db3/tutorial_js_table_of_contents_transforms.html">Image Transforms in OpenCV.js</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Fourier Transform </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h2>Goal </h2>
<ul>
<li>To find the Fourier Transform of images using OpenCV</li>
<li>Some applications of Fourier Transform</li>
<li>We will learn following functions : <b><a class="el" href="../../d2/de8/group__core__array.html#gadd6cf9baf2b8b704a11b5f04aaf4f39d" title="Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array...">cv.dft()</a></b> etc</li>
</ul>
<h2>Theory </h2>
<p>Fourier Transform is used to analyze the frequency characteristics of various filters. For images, <b>2D Discrete Fourier Transform (DFT)</b> is used to find the frequency domain. A fast algorithm called <b>Fast Fourier Transform (FFT)</b> is used for calculation of DFT. Details about these can be found in any image processing or signal processing textbooks.</p>
<p>For a sinusoidal signal, \(x(t) = A \sin(2 \pi ft)\), we can say \(f\) is the frequency of signal, and if its frequency domain is taken, we can see a spike at \(f\). If signal is sampled to form a discrete signal, we get the same frequency domain, but is periodic in the range \([- \pi, \pi]\) or \([0,2\pi]\) (or \([0,N]\) for N-point DFT). You can consider an image as a signal which is sampled in two directions. So taking fourier transform in both X and Y directions gives you the frequency representation of image.</p>
<p>More intuitively, for the sinusoidal signal, if the amplitude varies so fast in short time, you can say it is a high frequency signal. If it varies slowly, it is a low frequency signal. You can extend the same idea to images. Where does the amplitude varies drastically in images ? At the edge points, or noises. So we can say, edges and noises are high frequency contents in an image. If there is no much changes in amplitude, it is a low frequency component.</p>
<p>Performance of DFT calculation is better for some array size. It is fastest when array size is power of two. The arrays whose size is a product of 2’s, 3’s, and 5’s are also processed quite efficiently. So if you are worried about the performance of your code, you can modify the size of the array to any optimal size (by padding zeros) before finding DFT. OpenCV provides a function, <b><a class="el" href="../../d2/de8/group__core__array.html#ga6577a2e59968936ae02eb2edde5de299" title="Returns the optimal DFT size for a given vector size. ">cv.getOptimalDFTSize()</a></b> for this.</p>
<p>Now we will see how to find the Fourier Transform.</p>
<h2>Fourier Transform in OpenCV </h2>
<p>Performance of DFT calculation is better for some array size. It is fastest when array size is power of two. The arrays whose size is a product of 2’s, 3’s, and 5’s are also processed quite efficiently. So if you are worried about the performance of your code, you can modify the size of the array to any optimal size (by padding zeros). So how do we find this optimal size ? OpenCV provides a function, <a class="el" href="../../d2/de8/group__core__array.html#ga6577a2e59968936ae02eb2edde5de299" title="Returns the optimal DFT size for a given vector size. ">cv.getOptimalDFTSize()</a> for this.</p>
<p>We use the functions: <b><a class="el" href="../../d2/de8/group__core__array.html#gadd6cf9baf2b8b704a11b5f04aaf4f39d" title="Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array...">cv.dft</a> (src, dst, flags = 0, nonzeroRows = 0)</b></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">src</td><td>input array that could be real or complex. </td></tr>
    <tr><td class="paramname">dst</td><td>output array whose size and type depends on the flags. </td></tr>
    <tr><td class="paramname">flags</td><td>transformation flags, representing a combination of the <a class="el" href="../../d2/de8/group__core__array.html#gaf4dde112b483b38175621befedda1f1c">cv.DftFlags</a> </td></tr>
    <tr><td class="paramname">nonzeroRows</td><td>when the parameter is not zero, the function assumes that only the first nonzeroRows rows of the input array (DFT_INVERSE is not set) or only the first nonzeroRows of the output array (DFT_INVERSE is set) contain non-zeros, thus, the function can handle the rest of the rows more efficiently and save some time; this technique is very useful for calculating array cross-correlation or convolution using DFT.</td></tr>
  </table>
  </dd>
</dl>
<p><b><a class="el" href="../../d2/de8/group__core__array.html#ga6577a2e59968936ae02eb2edde5de299" title="Returns the optimal DFT size for a given vector size. ">cv.getOptimalDFTSize</a> (vecsize)</b></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">vecsize</td><td>vector size.</td></tr>
  </table>
  </dd>
</dl>
<p><b><a class="el" href="../../d2/de8/group__core__array.html#ga2ac1049c2c3dd25c2b41bffe17658a36" title="Forms a border around an image. ">cv.copyMakeBorder</a> (src, dst, top, bottom, left, right, borderType, value = new <a class="el" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">cv.Scalar()</a>)</b></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">src</td><td>input array that could be real or complex. </td></tr>
    <tr><td class="paramname">dst</td><td>output array whose size and type depends on the flags. </td></tr>
    <tr><td class="paramname">top</td><td>parameter specifying how many top pixels in each direction from the source image rectangle to extrapolate. </td></tr>
    <tr><td class="paramname">bottom</td><td>parameter specifying how many bottom pixels in each direction from the source image rectangle to extrapolate. </td></tr>
    <tr><td class="paramname">left</td><td>parameter specifying how many left pixels in each direction from the source image rectangle to extrapolate. </td></tr>
    <tr><td class="paramname">right</td><td>parameter specifying how many right pixels in each direction from the source image rectangle to extrapolate. </td></tr>
    <tr><td class="paramname">borderType</td><td>border type. </td></tr>
    <tr><td class="paramname">value</td><td>border value if borderType == <a class="el" href="../../d2/de8/group__core__array.html#gga209f2f4869e304c82d07739337eae7c5aed2e4346047e265c8c5a6d0276dcd838" title="iiiiii|abcdefgh|iiiiiii with some specified i ">cv.BORDER_CONSTANT</a>.</td></tr>
  </table>
  </dd>
</dl>
<p><b><a class="el" href="../../d2/de8/group__core__array.html#ga6d3b097586bca4409873d64a90fe64c3" title="Calculates the magnitude of 2D vectors. ">cv.magnitude</a> (x, y, magnitude)</b></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">x</td><td>floating-point array of x-coordinates of the vectors. </td></tr>
    <tr><td class="paramname">y</td><td>floating-point array of y-coordinates of the vectors; it must have the same size as x. </td></tr>
    <tr><td class="paramname">magnitude</td><td>output array of the same size and type as x.</td></tr>
  </table>
  </dd>
</dl>
<p><b><a class="el" href="../../d2/de8/group__core__array.html#ga0547c7fed86152d7e9d0096029c8518a" title="Divides a multi-channel array into several single-channel arrays. ">cv.split</a> (m, mv)</b></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">m</td><td>input multi-channel array. </td></tr>
    <tr><td class="paramname">mv</td><td>output vector of arrays; the arrays themselves are reallocated, if needed.</td></tr>
  </table>
  </dd>
</dl>
<p><b><a class="el" href="../../d2/de8/group__core__array.html#ga7d7b4d6c6ee504b30a20b1680029c7b4" title="Creates one multi-channel array out of several single-channel ones. ">cv.merge</a> (mv, dst)</b></p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">mv</td><td>input vector of matrices to be merged; all the matrices in mv must have the same size and the same depth. </td></tr>
    <tr><td class="paramname">dst</td><td>output array of the same size and the same depth as mv[0]; The number of channels will be the total number of channels in the matrix array.</td></tr>
  </table>
  </dd>
</dl>
<h2>Try it </h2>
<p> 
<iframe src="../../js_fourier_transform_dft.html" width="100%"
        onload="this.style.height=this.contentDocument.body.scrollHeight +'px';">
</iframe>
 </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:37 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
